<?php

	include_once('compare_display.php');
	include_once('classes/devices.php');
	include_once('classes/view.php');
	
	View::displayHeader();
	
	$MyObject = new Devices();
	$MyList = $MyObject -> GetProcessors();
	DisplayScript();
	DisplayCompare::DisplayDevice($MyList, "processor", "Porównanie procesorów");

	$MyTable = array(	
						"typ" => "Typ: ",
						"ilosc_rdzeni" => "Ilość rdzeni: ",
						"zlacze" => "Złącze: ",
						"czestotliwosc" => "Częstotliwość zegara: ",
						"technologia" => "Technologia [u]: ",
						"wydzielana_moc" => "Wydzielana moc [W]: ",
						"lone" => "L1 Cache [kB]: ",
						"ltwo" => "L2 Cache [kB]: ",
						"lthree" => "L3 Cache [kB]: "
					);
					
	$MyTable2 = array(	
						"typs" => "Typ: ",
						"ilosc_rdzenis" => "Ilość rdzeni: ",
						"zlaczes" => "Złącze: ",
						"czestotliwoscs" => "Częstotliwość zegara: ",
						"technologias" => "Technologia [u]: ",
						"wydzielana_mocs" => "Wydzielana moc [W]: ",
						"lones" => "L1 Cache [kB]: ",
						"ltwos" => "L2 Cache [kB]: ",
						"lthrees" => "L3 Cache [kB]: "
					);
	
	echo '<tr>';
	echo '<td>
			<table border="0" class="tableTest"><br />';
	
	foreach($MyTable as $MyId => $MyText){
		echo '	<tr>
					<td class="tableTd"><i><p align=\'right\'>'. $MyText . '&nbsp;&nbsp;</p></i></td>
					<td id="'. $MyId . '"></td>
				</tr>';
	}
	
	echo '</table>
		</td>
		<td>
			<table border="0" class="tableTest"><br />';
	
	foreach($MyTable2 as $MyId => $MyText){
		echo '	<tr>
					<td class="tableTd"><i><p align=\'right\'>'. $MyText . '&nbsp;&nbsp;</p></i></td>
					<td id="'. $MyId . '"></td>
				</tr>';
	}
	
	echo '</table>
		</td>
		</tr></table></div></form><br /><br /><br /><br />';
	
	View::displayFooter();
	
	function DisplayScript(){
		echo '<script type="text/javascript">
			var xmlHttp;
			var first;
			
			function showXmlDevice(pDevId, pKindDevice, pFirst){
				xmlHttp=GetXmlHttpObject();
				if (xmlHttp == null){
					alert ("Browser does not support HTTP Request");
					return;
				} 
				var url = "compare_get.php";
				url = url + "?kind_device=" + pKindDevice;
				url = url + "&dev_id=" + pDevId;
				url = url + "&first=" + pFirst;
				first = pFirst
				
				xmlHttp.onreadystatechange=stateChanged;
				xmlHttp.open("GET", url, true);
			 	xmlHttp.send(null);
			 }
			
			function stateChanged(){ 
				if (xmlHttp.readyState==4 || xmlHttp.readyState == "complete"){
					xmlDoc=xmlHttp.responseXML;
					if (first == "1"){
						document.getElementById("typ").innerHTML = xmlDoc.getElementsByTagName("typ")[0].childNodes[0].nodeValue;
						document.getElementById("ilosc_rdzeni").innerHTML = xmlDoc.getElementsByTagName("ilosc_rdzeni")[0].childNodes[0].nodeValue;
						document.getElementById("zlacze").innerHTML = xmlDoc.getElementsByTagName("zlacze")[0].childNodes[0].nodeValue;
						document.getElementById("czestotliwosc").innerHTML = xmlDoc.getElementsByTagName("czestotliwosc")[0].childNodes[0].nodeValue;
						document.getElementById("technologia").innerHTML = xmlDoc.getElementsByTagName("technologia")[0].childNodes[0].nodeValue;
						document.getElementById("wydzielana_moc").innerHTML = xmlDoc.getElementsByTagName("wydzielana_moc")[0].childNodes[0].nodeValue;
						document.getElementById("lone").innerHTML = xmlDoc.getElementsByTagName("lone")[0].childNodes[0].nodeValue;
						document.getElementById("ltwo").innerHTML = xmlDoc.getElementsByTagName("ltwo")[0].childNodes[0].nodeValue;
						document.getElementById("lthree").innerHTML = xmlDoc.getElementsByTagName("lthree")[0].childNodes[0].nodeValue;
					} else {
						document.getElementById("typs").innerHTML = xmlDoc.getElementsByTagName("typs")[0].childNodes[0].nodeValue;
						document.getElementById("ilosc_rdzenis").innerHTML = xmlDoc.getElementsByTagName("ilosc_rdzenis")[0].childNodes[0].nodeValue;
						document.getElementById("zlaczes").innerHTML = xmlDoc.getElementsByTagName("zlaczes")[0].childNodes[0].nodeValue;
						document.getElementById("czestotliwoscs").innerHTML = xmlDoc.getElementsByTagName("czestotliwoscs")[0].childNodes[0].nodeValue;
						document.getElementById("technologias").innerHTML = xmlDoc.getElementsByTagName("technologias")[0].childNodes[0].nodeValue;
						document.getElementById("wydzielana_mocs").innerHTML = xmlDoc.getElementsByTagName("wydzielana_mocs")[0].childNodes[0].nodeValue;
						document.getElementById("lones").innerHTML = xmlDoc.getElementsByTagName("lones")[0].childNodes[0].nodeValue;
						document.getElementById("ltwos").innerHTML = xmlDoc.getElementsByTagName("ltwos")[0].childNodes[0].nodeValue;
						document.getElementById("lthrees").innerHTML = xmlDoc.getElementsByTagName("lthrees")[0].childNodes[0].nodeValue;
					}
				}
			} 
			
			function GetXmlHttpObject() { 
				var objXMLHttp=null;
				if (window.XMLHttpRequest){
					objXMLHttp=new XMLHttpRequest();
				} else if (window.ActiveXObject)  {
					objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				return objXMLHttp;
			}
				</script>';
	}
?>